package serialize;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectOutput;
import java.io.ObjectOutputStream;
import java.io.OutputStream;
import java.util.Calendar;
import java.util.Date;

/**
 * 运行该类的main方法会抛出异常:NotSerializableException
 */
public class SerializationTest2 {

	public static void main(String[] args) throws IOException {
		
		Calendar calendar = Calendar.getInstance();
		calendar.clear();// 清除所有日历字段的值
		calendar.set( 1998 , 9 , 25 , 12, 30 );
		Date birthdate = calendar.getTime() ;
		
		Person p = new Person( 9527 , "华安" , '男' , birthdate );

		File f = new File( "student.ser" );
		OutputStream out = new FileOutputStream( f );
		ObjectOutput oo = new ObjectOutputStream(out);
		
		// 因为 Person 类没有实现 java.io.Serializable
		oo.writeObject( p ); // java.io.NotSerializableException: serialize.Person
		
		oo.close();
		out.close();
	}

}
